# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=dhall-docs
pkgver=1.0.11
pkgrel=62
pkgdesc="Generate HTML docs from a dhall package"
url="https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-docs"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base16-bytestring' 'haskell-cryptohash-sha256' 'dhall'
         'haskell-file-embed' 'haskell-lens-family-core' 'haskell-lucid' 'haskell-megaparsec'
         'haskell-mmark' 'haskell-optparse-applicative' 'haskell-path' 'haskell-path-io'
         'haskell-prettyprinter')
makedepends=('ghc' 'haskell-doctest' 'haskell-foldl' 'haskell-tasty' 'haskell-tasty-hunit'
             'haskell-tasty-silver' 'haskell-turtle')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('683c19cb31a2c0d919347f65bf6fd04950a9613db8d61288bf86b5968207a52edf986feb105ac287581f88b9e6ff686ec55abb8f0c25a65cde1c4537422c2e89')

prepare() {
  cd $pkgname-$pkgver
  sed -i '/Test-Suite doctest/a \    buildable: False' $pkgname.cabal
}

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
